package o;

import android.text.TextUtils;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import com.google.android.exoplayer2.text.webvtt.WebvttCssStyle;
import java.util.ArrayList;
import java.util.List;
import o.ako.a;

public final class akn extends ajh {
    private final anc ˊ = new anc();
    private final akj ˋ = new akj();
    private final akp ˎ = new akp();
    private final List<WebvttCssStyle> ˏ = new ArrayList();
    private final a ॱ = new a();

    protected /* synthetic */ aji ˎ(byte[] bArr, int i, boolean z) throws SubtitleDecoderException {
        return ˊ(bArr, i, z);
    }

    public akn() {
        super("WebvttDecoder");
    }

    protected akw ˊ(byte[] bArr, int i, boolean z) throws SubtitleDecoderException {
        this.ˊ.ॱ(bArr, i);
        this.ॱ.ˊ();
        this.ˏ.clear();
        try {
            akq.ˋ(this.ˊ);
            do {
            } while (!TextUtils.isEmpty(this.ˊ.ˊˋ()));
            List arrayList = new ArrayList();
            while (true) {
                int ˏ = ˏ(this.ˊ);
                if (ˏ == 0) {
                    return new akw(arrayList);
                }
                if (ˏ == 1) {
                    ˋ(this.ˊ);
                } else if (ˏ == 2) {
                    if (arrayList.isEmpty()) {
                        this.ˊ.ˊˋ();
                        WebvttCssStyle ˋ = this.ˋ.ˋ(this.ˊ);
                        if (ˋ != null) {
                            this.ˏ.add(ˋ);
                        }
                    } else {
                        throw new SubtitleDecoderException("A style block was found after the first cue.");
                    }
                } else if (ˏ == 3 && this.ˎ.ॱ(this.ˊ, this.ॱ, this.ˏ)) {
                    arrayList.add(this.ॱ.ˏ());
                    this.ॱ.ˊ();
                }
            }
        } catch (Exception e) {
            throw new SubtitleDecoderException(e);
        }
    }

    private static int ˏ(anc o_anc) {
        int i = 0;
        int i2 = -1;
        while (i2 == -1) {
            i2 = o_anc.ˋ();
            String ˊˋ = o_anc.ˊˋ();
            if (ˊˋ == null) {
                i = 0;
            } else if ("STYLE".equals(ˊˋ)) {
                i = 2;
            } else if (ˊˋ.startsWith("NOTE")) {
                i = 1;
            } else {
                i = 3;
            }
            int i3 = i2;
            i2 = i;
            i = i3;
        }
        o_anc.ˋ(i);
        return i2;
    }

    private static void ˋ(anc o_anc) {
        do {
        } while (!TextUtils.isEmpty(o_anc.ˊˋ()));
    }
}
